#include<iostream>

using namespace std;

const int N = 2e5 + 10;
int dp[N];
int n;
int main()
{
    cin >> n;
    int ret = -1e9 + 10;
    dp[0] = 0;
    for(int i = 1;i <= n;i ++)
    {
        int x; cin >> x;
        dp[i] = max(dp[i - 1] + x , x);
        ret = max(ret , dp[i]);
    }
    cout << ret << endl;
    return 0;
}